﻿Imports MeoTom.Core.BLL
Imports Microsoft.ApplicationBlocks.Data

Namespace DAL
    Public Class CommentProvider
        Inherits DataAccess

        Public util As New Utilities.Common()

        Public Sub New()

        End Sub

        Public Sub Create(ByVal cm As Comments)
            Dim param(9) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@AddedBy", SqlDbType.NVarChar, 50)
            param(0).Value = util.NoHTML(cm.AddedBy)
            param(1) = New SqlClient.SqlParameter("@AddedByEmail", SqlDbType.VarChar, 150)
            param(1).Value = util.NoHTML(cm.AddedByEmail)
            param(2) = New SqlClient.SqlParameter("@AddedByIP", SqlDbType.VarChar, 20)
            param(2).Value = cm.AddedByIP
            param(3) = New SqlClient.SqlParameter("@Body", SqlDbType.NVarChar, 4000)
            param(3).Value = cm.Body
            param(4) = New SqlClient.SqlParameter("@ArticleId", SqlDbType.Int, 4)
            param(4).Value = cm.ArticleId
            param(5) = New SqlClient.SqlParameter("@AddedByURL", SqlDbType.VarChar, 550)
            param(5).Value = cm.AddedByURL
            param(6) = New SqlClient.SqlParameter("@PageID", SqlDbType.VarChar, 30)
            param(6).Value = cm.PageID
            param(7) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(7).Value = Configs.SiteID
            param(8) = New SqlClient.SqlParameter("@IsAdmin", SqlDbType.Int, 4)
            param(8).Value = util.ConvertBoolToInt(cm.IsAdmin)

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Comments_Create", param)
        End Sub

        Public Sub Update(ByVal cm As Comments)
            Dim param(7) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@AddedBy", SqlDbType.NVarChar, 50)
            param(0).Value = util.NoHTML(cm.AddedBy)
            param(1) = New SqlClient.SqlParameter("@AddedByEmail", SqlDbType.VarChar, 150)
            param(1).Value = util.NoHTML(cm.AddedByEmail)
            param(2) = New SqlClient.SqlParameter("@Body", SqlDbType.NVarChar, 4000)
            param(2).Value = cm.Body
            param(3) = New SqlClient.SqlParameter("@AddedByURL", SqlDbType.VarChar, 550)
            param(3).Value = cm.AddedByURL
            param(4) = New SqlClient.SqlParameter("@CommentsID", SqlDbType.Int, 4)
            param(4).Value = cm.CommentsID
            param(5) = New SqlClient.SqlParameter("@Status", SqlDbType.Int, 4)
            param(5).Value = util.ConvertBoolToInt(cm.Status)
            param(6) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(6).Value = Configs.SiteID

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Comments_Update", param)
        End Sub

        Public Sub Delete(ByVal cm As Comments)
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@CommentsID", SqlDbType.Int, 4)
            param(0).Value = cm.CommentsID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Comments_Delete", param)
        End Sub

        Public Sub DeleteByArticle(ByVal objComment As Comments)
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@ArticleID", SqlDbType.Int, 4)
            param(0).Value = objComment.ArticleId

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Comments_DeleteByArticle", param)
        End Sub

        Public Sub DeleteByPage(ByVal objComment As Comments)
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@ArticleID", SqlDbType.VarChar, 30)
            param(0).Value = objComment.PageID

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Comments_DeleteByPage", param)
        End Sub

        Public Sub UpdateStatus(ByVal cm As Comments)
            Dim param(3) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@Status", SqlDbType.Int, 4)
            param(0).Value = util.ConvertBoolToInt(cm.Status)
            param(1) = New SqlClient.SqlParameter("@CommentsID", SqlDbType.Int, 4)
            param(1).Value = cm.CommentsID
            param(2) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(2).Value = Configs.SiteID

            SqlHelper.ExecuteNonQuery(strConn, CommandType.StoredProcedure, "Justin_Comments_UpdateStatus", param)
        End Sub

        Public Function GetByID(ByVal cm As Comments) As SqlClient.SqlDataReader
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@CommentsID", SqlDbType.Int, 4)
            param(0).Value = cm.CommentsID
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Comments_GetByID", param)
        End Function

        Public Function GetByArticle(ByVal cm As Comments) As DataSet
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@ArticleId", SqlDbType.Int, 4)
            param(0).Value = cm.ArticleId

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_Comments_GetByArticleID", param)
        End Function

        Public Function GetByArticleLow(ByVal cm As Comments) As SqlClient.SqlDataReader
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@ArticleId", SqlDbType.Int, 4)
            param(0).Value = cm.ArticleId

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Comments_GetByArticleID", param)
        End Function

        Public Function GetByPage(ByVal objComment As Comments) As DataSet
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@PageID", SqlDbType.VarChar, 30)
            param(0).Value = objComment.PageID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_Comments_GetByPageID", param)
        End Function

        Public Function GetByPageLow(ByVal objComment As Comments) As SqlClient.SqlDataReader
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@PageID", SqlDbType.VarChar, 30)
            param(0).Value = objComment.PageID

            Return SqlHelper.ExecuteReader(strConn, CommandType.StoredProcedure, "Justin_Comments_GetByPageID", param)
        End Function

        'Public Function Get

        Public Function GetAll() As DataSet
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(0).Value = Configs.SiteID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_Comments_GetAll", param)
        End Function

        Public Function GetAllPageComment() As DataSet
            Dim param(1) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(0).Value = Configs.SiteID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_Comments_GetAllPage", param)
        End Function

        Public Function Find(ByVal cm As Comments) As DataSet
            Dim param(2) As SqlClient.SqlParameter
            param(0) = New SqlClient.SqlParameter("@KeyWord", SqlDbType.NVarChar, 250)
            param(0).Value = "%" & cm.KeyWord & "%"
            param(1) = New SqlClient.SqlParameter("@SiteID", SqlDbType.Int, 4)
            param(1).Value = Configs.SiteID

            Return SqlHelper.ExecuteDataset(strConn, CommandType.StoredProcedure, "Justin_Comments_Find", param)
        End Function
    End Class
End Namespace